package cn.amebius.simpledocker.config;

import cn.amebius.simpledocker.entity.dto.UserRoleInfoDto;
import cn.amebius.simpledocker.service.UserService;
import cn.dev33.satoken.stp.StpInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 自定义权限加载接口实现类
 * @author 阿伟
 * @date 2023/7/31 19:54
 */
@Component
public class SatokenFaceImpl implements StpInterface {

    @Autowired
    UserService userService;

    @Override
    public List<String> getPermissionList(Object loginId, String s) {
        Set<String> userPermission = userService.getUserPermission((int) loginId);
        ArrayList<String> retList = new ArrayList<>();
        retList.addAll(userPermission);
        return retList;
    }

    @Override
    public List<String> getRoleList(Object loginId, String s) {
        UserRoleInfoDto urid = userService.getUserRole((int) loginId);
        ArrayList<String> retList = new ArrayList<>();
        retList.add(urid.getDesignation());
        return retList;
    }


}
